package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocCreditBasicDao;
import com.irdstudio.cdp.pboc.service.domain.PbocCreditBasic;
import com.irdstudio.cdp.pboc.service.facade.PbocCreditBasicService;
import com.irdstudio.cdp.pboc.service.vo.PbocCreditBasicVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 贷记卡基本信息				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocCreditBasicService")
public class PbocCreditBasicServiceImpl implements PbocCreditBasicService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocCreditBasicServiceImpl.class);

	@Autowired
	private PbocCreditBasicDao pbocCreditBasicDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocCreditBasic(PbocCreditBasicVO inPbocCreditBasicVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocCreditBasicVo.toString());
		int num = 0;
		try {
			PbocCreditBasic pbocCreditBasic = new PbocCreditBasic();
			beanCopy(inPbocCreditBasicVo, pbocCreditBasic);
			num = pbocCreditBasicDao.insertPbocCreditBasic(pbocCreditBasic);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocCreditBasicVO inPbocCreditBasicVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocCreditBasicVo);
		int num = 0;
		try {
			PbocCreditBasic pbocCreditBasic = new PbocCreditBasic();
			beanCopy(inPbocCreditBasicVo, pbocCreditBasic);
			num = pbocCreditBasicDao.deleteByPk(pbocCreditBasic);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditBasicVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocCreditBasicVO inPbocCreditBasicVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocCreditBasicVo.toString());
		int num = 0;
		try {
			PbocCreditBasic pbocCreditBasic = new PbocCreditBasic();
			beanCopy(inPbocCreditBasicVo, pbocCreditBasic);
			num = pbocCreditBasicDao.updateByPk(pbocCreditBasic);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditBasicVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocCreditBasicVO queryByPk(PbocCreditBasicVO inPbocCreditBasicVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocCreditBasicVo);
		try {
			PbocCreditBasic queryPbocCreditBasic = new PbocCreditBasic();
			beanCopy(inPbocCreditBasicVo, queryPbocCreditBasic);
			PbocCreditBasic queryRslPbocCreditBasic = pbocCreditBasicDao.queryByPk(queryPbocCreditBasic);
			if (Objects.nonNull(queryRslPbocCreditBasic)) {
				PbocCreditBasicVO outPbocCreditBasicVo = beanCopy(queryRslPbocCreditBasic, new PbocCreditBasicVO());
				logger.debug("当前查询结果为:"+ outPbocCreditBasicVo.toString());
				return outPbocCreditBasicVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditBasicVO> queryAllOwner(PbocCreditBasicVO pbocCreditBasicVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocCreditBasicVO> list = null;
		try {
			List<PbocCreditBasic> pbocCreditBasics = pbocCreditBasicDao.queryAllOwnerByPage(pbocCreditBasicVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocCreditBasics.size());
			pageSet(pbocCreditBasics, pbocCreditBasicVo);
			list = (List<PbocCreditBasicVO>) beansCopy(pbocCreditBasics, PbocCreditBasicVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditBasicVO> queryAllCurrOrg(PbocCreditBasicVO pbocCreditBasicVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocCreditBasic> pbocCreditBasics = pbocCreditBasicDao.queryAllCurrOrgByPage(pbocCreditBasicVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocCreditBasics.size());
		List<PbocCreditBasicVO> list = null;
		try {
			pageSet(pbocCreditBasics, pbocCreditBasicVo);
			list = (List<PbocCreditBasicVO>) beansCopy(pbocCreditBasics, PbocCreditBasicVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditBasicVO> queryAllCurrDownOrg(PbocCreditBasicVO pbocCreditBasicVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocCreditBasic> pbocCreditBasics = pbocCreditBasicDao.queryAllCurrDownOrgByPage(pbocCreditBasicVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocCreditBasics.size());
		List<PbocCreditBasicVO> list = null;
		try {
			pageSet(pbocCreditBasics, pbocCreditBasicVo);
			list = (List<PbocCreditBasicVO>) beansCopy(pbocCreditBasics, PbocCreditBasicVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}

	/**
	 * 需求编号:2019D0519
	 * 问题编号:
	 * 开发人员: caoxin
	 * 创建日期:2019/7/19
	 * 功能描述:根据报告编号进行查询
	 * 修改日期:2019/7/19
	 * 修改描述:
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<PbocCreditBasicVO> selectByReportId(PbocCreditBasicVO pbocCreditBasicVO)  throws Exception {
		List<PbocCreditBasicVO> vos = null;
		logger.debug("当前查询参数信息为:"+ pbocCreditBasicVO);
		try {
			PbocCreditBasic pbocCreditBasic = new PbocCreditBasic();
			beanCopy(pbocCreditBasicVO, pbocCreditBasic);
			List<PbocCreditBasic> queryRslPbocCreditBasic = pbocCreditBasicDao.selectByReportId(pbocCreditBasic);
			vos = (List<PbocCreditBasicVO>) beansCopy(queryRslPbocCreditBasic, PbocCreditBasicVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return vos;
	}
}
